package com.aplink.generic.pojo.controlspec;

import android.content.pm.PackageManager.NameNotFoundException;

import com.aplink.generic.GenericFragment;
import com.aplink.generic.util.objectrule.Target;
import com.aplink.generic.util.objectrule.TargetCollection;
import com.aplink.generic.util.validation.Validation;

public class ButtonSpec extends ControlSpec {
	private static final long serialVersionUID = -1153277759037698542L;
	private TargetCollection mTargetCollection;
	private Validation mValidation;

	public ButtonSpec(final TargetCollection targetCollection) {
		this.mTargetCollection = targetCollection;
	}

	public ButtonSpec() {
		mTargetCollection = new TargetCollection();
	}

	public TargetCollection getTargetCollection() {
		return this.mTargetCollection;
	}

	public Validation getValidation() {
		return mValidation;
	}

	public void linkToNextPage(final GenericFragment genericFragment)
	        throws InstantiationException, IllegalAccessException,
	        ClassNotFoundException, NameNotFoundException {
		final Target target = this.mTargetCollection
		        .getTargetClass(genericFragment.getSelectedObject());
		genericFragment.startActivity(target.getTargetClass(),
		        target.getPassingValue());
	}

	public void setTargetCollection(final TargetCollection targetCollection) {
		this.mTargetCollection = targetCollection;
	}

	public void setValidation(final Validation validation) {
		mValidation = validation;
	}

}
